import 'package:flutter/material.dart';

import '../l10n/app_localizations.dart';

class BottomNavigationBarNv extends StatefulWidget{
  final ValueChanged<int>? onIndexChanged; // 新增回调属性

  const BottomNavigationBarNv({Key? key, this.onIndexChanged}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
     return _BottomNavigationBarIndex();
  }
}
class _BottomNavigationBarIndex extends State<BottomNavigationBarNv>{
  int _currentIndex=0;
  void onTapHandlerTap(int indexType){
    setState(() {
      _currentIndex=indexType;
    });
    //回调界面
    widget.onIndexChanged?.call(indexType);
  }

  @override
  Widget build(BuildContext context) {
     return BottomNavigationBar(
         type: BottomNavigationBarType.fixed,//不设置这个属性最多只能显示3
         fixedColor: Colors.black,
         currentIndex: _currentIndex,
         onTap: onTapHandlerTap,
         items: [
           BottomNavigationBarItem(icon: Icon(Icons.explore),label: AppLocalizations.of(context)!.home),
           BottomNavigationBarItem(icon: Icon(Icons.history),label: AppLocalizations.of(context)!.plant),
           BottomNavigationBarItem(icon: Icon(Icons.hiking_outlined),label: AppLocalizations.of(context)!.device),
           BottomNavigationBarItem(icon: Icon(Icons.person),label: AppLocalizations.of(context)!.me),
         ]);
  }

}